import { matchPath } from '@szzj/utils';
import useTree from '../useTree';
var useRoutes = function useRoutes(routes, options) {
  var routesManager = useTree(routes, {
    uniqueKey: options.uniqueKey ? options.uniqueKey : 'component',
    childrenKey: options.childrenKey ? options.childrenKey : 'routes'
  });
  var authFilter = options.authFilter || function (route) {
    return route;
  };
  return {
    getAuthedRoutes: function getAuthedRoutes(cb) {
      // @ts-ignore
      return routesManager.filter(cb ? cb : authFilter);
    },
    getMatchedRoutes: function getMatchedRoutes(pathname) {
      var matchedRoutes = [];
      // @ts-ignore
      routesManager.forEach(
      // @ts-ignore
      function (route) {
        if (matchPath(pathname, {
          path: route.path
        })) {
          matchedRoutes.push(route);
        }
      }, {
        order: 'dlr'
      });
      return matchedRoutes;
    }
  };
};
export default useRoutes;